import {fromJS} from "immutable";
import {
    click_first_menu,
    click_second_menu,
    request_sytem_data_tag,
    save_system_type_data,
    update_system_data
} from "../../body/contants";

const defaultStatus = fromJS({
    systemTypeFirstData: [],  //一级目录里面包含了二级目录的数据
    systemTypeSecondData: [],
    firstChoice: 0,
    secondChoice: 0,
    systemArtList: [],
    artPage: 0,
    updateTag: true,
    cid:-1,
});

export default (status = defaultStatus, action) => {
    switch (action.type) {
        case save_system_type_data:

            return status.merge({
                systemTypeFirstData: fromJS(action.systemTypeFirstData),
                systemTypeSecondData: fromJS(action.systemTypeSecondData)
            });

        case click_first_menu:
            return status.merge({
                firstChoice: action.firstChoice,
                secondChoice: 0,
                systemTypeSecondData: action.systemTypeSecondData,
            });
        case click_second_menu:
            return status.merge({
                secondChoice: action.secondChoice
            });

        case update_system_data:
            let newState;
            if (action.pageIndex === 0) {
                newState = status.merge({
                    systemArtList: fromJS(action.systemArtList),
                    artPage: 0,
                    cid:action.cid
                });
            } else {
                newState = status.merge({
                    systemArtList: status.get("systemArtList").concat(fromJS(action.systemArtList)),
                    artPage: action.pageIndex,
                    cid:action.cid
                });
            }
            return newState;
        case request_sytem_data_tag:
            return status.set("updateTag",action.bool);
        default:
            return status;
    }
}